const express = require('express')
const { getUserList, modifyUserlist, deleteUserlist } = require('../../model/mongo')
const router = express.Router()

router.get('/list', async (req, res) => {
    const result = {
        code: 200,
        msg: '获取用户列表',
        data: []
    }
    try {
        result.data = await getUserList()
    } catch (err) {
        result.code = 400
    }
    res.send(JSON.stringify(result))
})

router.post('/modify', async (req, res) => {
    let { id, data } = req.body
    let result = {
        code: 200
    }
    result.msg = await modifyUserlist(id, data)
    res.send(JSON.stringify(result))
})

router.post('/delete', async (req, res) => {
    let { id } = req.body
    let result = {
        code: 200
    }
    result.msg = await deleteUserlist(id)
    res.send(JSON.stringify(result))
})

module.exports = router
